import * as THREE from 'three';
const model = new THREE.Group();
const geometry = new THREE.BoxGeometry(1, 1, 1);
const material = new THREE.MeshBasicMaterial({color: 0x00ff00});
const mesh = new THREE.Mesh(geometry,material)

const material2 = new THREE.MeshBasicMaterial({color: 0x00ffff});
const person = new THREE.Mesh(geometry,material2)
person.position.set(0, 0, 2);//人位置
const a = new THREE.Vector3(0,0,-1)//人看的方向是z轴的负半轴方向
mesh.position.set(3, 0, -3)//物体的位置

const R = 20//扇形的半径
const angle = 60//扇形的角度
// 获取物体到人的距离
const b = mesh.position.clone().sub(person.position)//物体到人的直线
const L = b.length()//直线长度
if(L>R){
    console.log('人不在扇形的范围内！');
}else{
    // 当L小于R时，判断角度是否小于扇形角度的一半
    // const cos =a.dot(b.clone().normalize());
    const cos =b.clone().normalize().dot(a);
    // 将angle角度转换为弧度
    const rad = THREE.MathUtils.degToRad(angle);
    if(cos>Math.cos(rad/2)){
        console.log('在扇形范围内！');
    }else{
        console.log('不在扇形范围内！');
    }
}
model.add(mesh,person);


export default {model};